#define _CRT_SECURE_NO_WARNINGS

#include<assert.h>
#include<stdio.h>
#include<stdlib.h>

int missingNumber(int* nums, int numsSize) {
    int* tmp = malloc((numsSize + 1) * sizeof(int));
    if (tmp == NULL)
    {
        perror("malloc failed");
        exit(-1);
    }
    int i = 0;
    for (i = 0; i <= numsSize; i++)
    {
        tmp[i] = i;
    }
    for (i = 0; i < numsSize; i++)
    {
        tmp[nums[i]] = -1;
    }
    for (i = 0; i <= numsSize; i++)
    {
        if (tmp[i] != -1)
            return tmp[i];
    }
    free(tmp);
    tmp = NULL;
    return -1;
}

int main()
{
    int a[] = { 9,6,4,2,3,5,7,0,1 };

    int ret = missingNumber(a, 9);

    printf("%d\n", ret);

	return 0;
}

